// 自定义全局指令
import { useIntersectionObserver } from '@vueuse/core'

export const lazyPlugin = {
  install(app) {
    // 自定义全局指令
    app.directive('img-lazy', {
      mounted(el, binding) {
        // console.log(el)
        // console.log(binding)

        const {stop} = useIntersectionObserver(
          el,
          ([entry], observerElement) => {
            console.log(entry?.isIntersecting || false)
            if (entry?.isIntersecting) {
              el.src = binding.value
              stop()
            }
          },
        )
      }
    })
  }
}
